import 'dart:ffi';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:full_display/unit/asset_utils/asset_utils.dart';

class ButtonListWidget extends StatefulWidget {
  final List btnList;
  Function(int index, BuildContext context) tapAction;
  bool isBg;
  ButtonListWidget(
      {required this.btnList,
      required this.tapAction,
      required this.isBg,
      Key? key})
      : super(key: key);

  @override
  State<ButtonListWidget> createState() => _ButtonListWidgetState();
}

class _ButtonListWidgetState extends State<ButtonListWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 20.0.H, bottom: 20.0.H),
      decoration: widget.isBg
          ? const BoxDecoration(
              color: ColorPlate.backgroundOpacity0,
              borderRadius: BorderRadius.all(Radius.circular(12.0)),
            )
          : const BoxDecoration(),
      child: Row(
          children: widget.btnList.map((e) => _getItem(e, context)).toList()),
    );
  }

  Widget _getItem(Map data, BuildContext context) {
    // print("data ----> ${data}");
    return Expanded(
      child: InkWell(
        onTap: () {
          widget.tapAction(data['index'], context);
        },
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Image.asset(
                height: 30.0.H,
                width: 30.0.W,
                AssetUtils.getAsset2Image(data['img'].toString()),
              ),
              Container(height: 10.0.H),
              Text(
                data['text'],
                style: StandardTextStyle.textWhite16Style,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
